package com.example.demo;

import java.text.DecimalFormat;
public class TelFee {
    public String fee(String sd1, String sd2) {

        double telFee;
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//字符输入流
//        try {
//            System.out.println("输入开始时间（如20170102030405）:");
//             sd1= br.readLine();//按行读入
//            System.out.println("输入停止时间（如20170102030405）:");
//             sd2= br.readLine();
//        sd1 = "20210303010101";
//        sd2 = "20210409000000";


            HoldingTime ht = new HoldingTime(sd1,sd2);

            System.out.println("电话接通时间："+ht.DateFormate(ht.startT));
            System.out.println("电话结束时间："+ht.DateFormate(ht.endT));

            DecimalFormat    df   = new DecimalFormat("######0.00");
            long minute = ht.getHoldingTime();
            //计算话费
            if(minute <= 20){
                telFee = 0.05*minute;
            }else{
                telFee = 1.00 + (minute - 20)*0.1;
            }
            System.out.println("通话时间："+minute+"分钟");
            System.out.println("通话话费："+df.format(telFee)+"美元");
//        }catch (IOException e) {
//            e.printStackTrace();
//        }
//        return (minute);
        return df.format(telFee);
    }
}